<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="ID" prop="alarmId">
        <el-input
          v-model="queryParams.alarmId"
          placeholder="ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="终端设备编号 " prop="deviceNo">
        <el-input
          v-model="queryParams.deviceNo"
          placeholder="请输入终端设备编号 "
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="终端sim卡号 " prop="sim">
        <el-input
          v-model="queryParams.sim"
          placeholder="请输入终端sim卡号 "
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车辆id" prop="vehicleId">
        <el-input
          v-model="queryParams.vehicleId"
          placeholder="请输入车辆id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车牌号" prop="vehicleNo">
        <el-input
          v-model="queryParams.vehicleNo"
          placeholder="请输入车牌号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="报警产生时间" prop="startTime">
        <el-date-picker clearable
          v-model="queryParams.startTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择报警产生时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="报警结束时间" prop="endTime">
        <el-date-picker clearable
          v-model="queryParams.endTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择报警结束时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="驾驶员姓名" prop="driverName">
        <el-input
          v-model="queryParams.driverName"
          placeholder="请输入驾驶员姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="驾驶员身份证号" prop="driverCard">
        <el-input
          v-model="queryParams.driverCard"
          placeholder="请输入驾驶员身份证号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="报警信息来源" prop="warnSrc">
        <el-input
          v-model="queryParams.warnSrc"
          placeholder="请输入报警信息来源"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="报警开始经度" prop="startLon">
        <el-input
          v-model="queryParams.startLon"
          placeholder="请输入报警开始经度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="报警开始纬度" prop="startLat">
        <el-input
          v-model="queryParams.startLat"
          placeholder="请输入报警开始纬度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="报警结束速度" prop="startSpeed">
        <el-input
          v-model="queryParams.startSpeed"
          placeholder="请输入报警结束速度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="GPS方向角" prop="startDirection">
        <el-input
          v-model="queryParams.startDirection"
          placeholder="请输入GPS方向角"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车辆状态" prop="startState">
        <el-input
          v-model="queryParams.startState"
          placeholder="请输入车辆状态"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="报警结束经度" prop="endLon">
        <el-input
          v-model="queryParams.endLon"
          placeholder="请输入报警结束经度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="报警结束纬度" prop="endLat">
        <el-input
          v-model="queryParams.endLat"
          placeholder="请输入报警结束纬度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="报警结束速度" prop="endSpeed">
        <el-input
          v-model="queryParams.endSpeed"
          placeholder="请输入报警结束速度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="GPS方向角" prop="endDirection">
        <el-input
          v-model="queryParams.endDirection"
          placeholder="请输入GPS方向角"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="${comment}" prop="endState">
        <el-input
          v-model="queryParams.endState"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="报警处理状态 " prop="handleState">
        <el-input
          v-model="queryParams.handleState"
          placeholder="请输入报警处理状态 "
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="处理方式" prop="handleMethod">
        <el-input
          v-model="queryParams.handleMethod"
          placeholder="请输入处理方式"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="处理时间" prop="handleTime">
        <el-date-picker clearable
          v-model="queryParams.handleTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择处理时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="处理人" prop="handlePeople">
        <el-input
          v-model="queryParams.handlePeople"
          placeholder="请输入处理人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="处理结果描述" prop="handleDesc">
        <el-input
          v-model="queryParams.handleDesc"
          placeholder="请输入处理结果描述"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车辆颜色中文" prop="vehicleColor">
        <el-input
          v-model="queryParams.vehicleColor"
          placeholder="请输入车辆颜色中文"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="驾驶员id" prop="driverId">
        <el-input
          v-model="queryParams.driverId"
          placeholder="请输入驾驶员id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="附件数量" prop="fileNum">
        <el-input
          v-model="queryParams.fileNum"
          placeholder="请输入附件数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['alarm:alarmData:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['alarm:alarmData:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['alarm:alarmData:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['alarm:alarmData:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="alarmDataList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="预警信息ID" align="center" prop="id" />
      <el-table-column label="唯一ID" align="center" prop="alarmId" />
      <el-table-column label="报警状态" align="center" prop="alarmStatus" />
      <el-table-column label="终端设备编号" align="center" prop="deviceNo" />
      <el-table-column label="终端sim卡号" align="center" prop="sim" />
      <el-table-column label="车辆id" align="center" prop="vehicleId" />
      <el-table-column label="车牌号" align="center" prop="vehicleNo" />
      <el-table-column label="车辆类型" align="center" prop="vehicleType" />
      <el-table-column label="报警产生时间" align="center" prop="startTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.startTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="报警结束时间 " align="center" prop="endTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.endTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="驾驶员姓名" align="center" prop="driverName" />
      <el-table-column label="驾驶员身份证号" align="center" prop="driverCard" />
      <el-table-column label="报警信息来源" align="center" prop="warnSrc" />
      <el-table-column label="报警类型" align="center" prop="warnType" />
      <el-table-column label="报警描述" align="center" prop="warnContent" />
      <el-table-column label="报警开始经度" align="center" prop="startLon" />
      <el-table-column label="报警开始纬度" align="center" prop="startLat" />
      <el-table-column label="报警结束速度" align="center" prop="startSpeed" />
      <el-table-column label="GPS方向角" align="center" prop="startDirection" />
      <el-table-column label="车辆状态" align="center" prop="startState" />
      <el-table-column label="查看状态" align="center" prop="readStatus" />
      <el-table-column label="报警结束经度" align="center" prop="endLon" />
      <el-table-column label="报警结束纬度" align="center" prop="endLat" />
      <el-table-column label="报警结束速度" align="center" prop="endSpeed" />
      <el-table-column label="GPS方向角" align="center" prop="endDirection" />
      <el-table-column label="${comment}" align="center" prop="endState" />
      <el-table-column label="报警处理状态 " align="center" prop="handleState" />
      <el-table-column label="处理方式" align="center" prop="handleMethod" />
      <el-table-column label="处理时间" align="center" prop="handleTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.handleTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="处理人" align="center" prop="handlePeople" />
      <el-table-column label="处理结果描述" align="center" prop="handleDesc" />
      <el-table-column label="车辆颜色中文" align="center" prop="vehicleColor" />
      <el-table-column label="驾驶员id" align="center" prop="driverId" />
      <el-table-column label="附件数量" align="center" prop="fileNum" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['alarm:alarmData:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['alarm:alarmData:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改预警信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="唯一ID,用于关联报警数据(*必填)" prop="alarmId">
          <el-input v-model="form.alarmId" placeholder="请输入唯一ID,用于关联报警数据(*必填)" />
        </el-form-item>
        <el-form-item label="终端设备编号 " prop="deviceNo">
          <el-input v-model="form.deviceNo" placeholder="请输入终端设备编号 " />
        </el-form-item>
        <el-form-item label="终端sim卡号 " prop="sim">
          <el-input v-model="form.sim" placeholder="请输入终端sim卡号 " />
        </el-form-item>
        <el-form-item label="车辆id，关联mangroves_car_info,建立索引加速查询" prop="vehicleId">
          <el-input v-model="form.vehicleId" placeholder="请输入车辆id，关联mangroves_car_info,建立索引加速查询" />
        </el-form-item>
        <el-form-item label="车牌号(*必填)" prop="vehicleNo">
          <el-input v-model="form.vehicleNo" placeholder="请输入车牌号(*必填)" />
        </el-form-item>
        <el-form-item label="报警产生时间" prop="startTime">
          <el-date-picker clearable
            v-model="form.startTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择报警产生时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="报警结束时间 " prop="endTime">
          <el-date-picker clearable
            v-model="form.endTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择报警结束时间 ">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="驾驶员姓名,静态绑定的驾驶员,如果未录入则为空" prop="driverName">
          <el-input v-model="form.driverName" placeholder="请输入驾驶员姓名,静态绑定的驾驶员,如果未录入则为空" />
        </el-form-item>
        <el-form-item label="驾驶员身份证号，同上" prop="driverCard">
          <el-input v-model="form.driverCard" placeholder="请输入驾驶员身份证号，同上" />
        </el-form-item>
        <el-form-item label="报警信息来源{设备、平台}(*必填)" prop="warnSrc">
          <el-input v-model="form.warnSrc" placeholder="请输入报警信息来源{设备、平台}(*必填)" />
        </el-form-item>
        <el-form-item label="报警描述">
          <editor v-model="form.warnContent" :min-height="192"/>
        </el-form-item>
        <el-form-item label="报警开始经度" prop="startLon">
          <el-input v-model="form.startLon" placeholder="请输入报警开始经度" />
        </el-form-item>
        <el-form-item label="报警开始纬度" prop="startLat">
          <el-input v-model="form.startLat" placeholder="请输入报警开始纬度" />
        </el-form-item>
        <el-form-item label="报警结束速度" prop="startSpeed">
          <el-input v-model="form.startSpeed" placeholder="请输入报警结束速度" />
        </el-form-item>
        <el-form-item label="GPS方向角" prop="startDirection">
          <el-input v-model="form.startDirection" placeholder="请输入GPS方向角" />
        </el-form-item>
        <el-form-item label="车辆状态(*必填)" prop="startState">
          <el-input v-model="form.startState" placeholder="请输入车辆状态(*必填)" />
        </el-form-item>
        <el-form-item label="报警结束经度" prop="endLon">
          <el-input v-model="form.endLon" placeholder="请输入报警结束经度" />
        </el-form-item>
        <el-form-item label="报警结束纬度" prop="endLat">
          <el-input v-model="form.endLat" placeholder="请输入报警结束纬度" />
        </el-form-item>
        <el-form-item label="报警结束速度" prop="endSpeed">
          <el-input v-model="form.endSpeed" placeholder="请输入报警结束速度" />
        </el-form-item>
        <el-form-item label="GPS方向角" prop="endDirection">
          <el-input v-model="form.endDirection" placeholder="请输入GPS方向角" />
        </el-form-item>
        <el-form-item label="${comment}" prop="endState">
          <el-input v-model="form.endState" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="报警处理状态 " prop="handleState">
          <el-input v-model="form.handleState" placeholder="请输入报警处理状态 " />
        </el-form-item>
        <el-form-item label="处理方式{人工确认、对讲、文本下发}" prop="handleMethod">
          <el-input v-model="form.handleMethod" placeholder="请输入处理方式{人工确认、对讲、文本下发}" />
        </el-form-item>
        <el-form-item label="处理时间" prop="handleTime">
          <el-date-picker clearable
            v-model="form.handleTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择处理时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="处理人" prop="handlePeople">
          <el-input v-model="form.handlePeople" placeholder="请输入处理人" />
        </el-form-item>
        <el-form-item label="处理结果描述" prop="handleDesc">
          <el-input v-model="form.handleDesc" placeholder="请输入处理结果描述" />
        </el-form-item>
        <el-form-item label="车辆颜色中文" prop="vehicleColor">
          <el-input v-model="form.vehicleColor" placeholder="请输入车辆颜色中文" />
        </el-form-item>
        <el-form-item label="驾驶员id" prop="driverId">
          <el-input v-model="form.driverId" placeholder="请输入驾驶员id" />
        </el-form-item>
        <el-form-item label="附件数量" prop="fileNum">
          <el-input v-model="form.fileNum" placeholder="请输入附件数量" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listAlarmData, getAlarmData, delAlarmData, addAlarmData, updateAlarmData } from "@/api/alarm/alarmData";

export default {
  name: "AlarmData",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 预警信息表格数据
      alarmDataList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        alarmId: null,
        alarmStatus: null,
        deviceNo: null,
        sim: null,
        vehicleId: null,
        vehicleNo: null,
        vehicleType: null,
        startTime: null,
        endTime: null,
        driverName: null,
        driverCard: null,
        warnSrc: null,
        warnType: null,
        warnContent: null,
        startLon: null,
        startLat: null,
        startSpeed: null,
        startDirection: null,
        startState: null,
        readStatus: null,
        endLon: null,
        endLat: null,
        endSpeed: null,
        endDirection: null,
        endState: null,
        handleState: null,
        handleMethod: null,
        handleTime: null,
        handlePeople: null,
        handleDesc: null,
        vehicleColor: null,
        driverId: null,
        fileNum: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询预警信息列表 */
    getList() {
      this.loading = true;
      listAlarmData(this.queryParams).then(response => {
        this.alarmDataList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        alarmId: null,
        alarmStatus: null,
        deviceNo: null,
        sim: null,
        vehicleId: null,
        vehicleNo: null,
        vehicleType: null,
        startTime: null,
        endTime: null,
        driverName: null,
        driverCard: null,
        warnSrc: null,
        warnType: null,
        warnContent: null,
        startLon: null,
        startLat: null,
        startSpeed: null,
        startDirection: null,
        startState: null,
        readStatus: null,
        endLon: null,
        endLat: null,
        endSpeed: null,
        endDirection: null,
        endState: null,
        handleState: null,
        handleMethod: null,
        handleTime: null,
        handlePeople: null,
        handleDesc: null,
        vehicleColor: null,
        driverId: null,
        fileNum: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加预警信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getAlarmData(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改预警信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateAlarmData(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addAlarmData(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除预警信息编号为"' + ids + '"的数据项？').then(function() {
        return delAlarmData(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('alarm/alarmData/export', {
        ...this.queryParams
      }, `alarmData_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
